// pages/tabBar/index/search/se.js
const app = getApp()
import {
    _get,
    _post
} from '../../../../utils/httpUtils.js'
Page({
    data: {
        navbarData: {
            showCapsule: 1, //是否显示左上角图标
            title: '搜索' //导航栏 中间的标题
        },
        height: app.globalData.height,
        focus: true,
        keyword_list: [],
        keyword: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.getKeyword()
    },
    getKeyword() {
        _get('/api/Article/search', null, res => {
            if (res.data.code == 1) {
                this.setData({
                    keyword_list: res.data.data.keyword_list
                })
            } else {
                wx.showToast({
                    title: res.data.msg,
                    duration: 2000,
                    icon: 'none'
                })
            }
        })

    },

    bindinput(e) {
        this.setData({
            keyword: e.detail.value
        })
    },
    _navback() { //返回
        wx.navigateBack()
    },
    search(e) {
        let key = e.currentTarget.dataset.key
        let _data = {
            keyword: this.data.keyword || key,
            page: 1
        }
        if (!_data.keyword) {
            wx.showToast({
                title: '请输入关键字',
                duration: 2000,
                icon: 'none'
            })
            return
        }
        wx.navigateTo({
            url: `/pages/tabBar/index/searchresult/searchresult?queryData=${JSON.stringify(_data)}`,
        })
    }
})